home *** CD-ROM | disk | FTP | other *** search
/ Champak 125 / Vol 125 (Damaged).iso / games / rabbit_r.swf / scripts / __Packages / disney / rabbitRivalry / ents / Player.as < prev    next >
Encoding:
Text File  |  2009-06-09  |  9.1 KB  |  339 lines

  1. class disney.rabbitRivalry.ents.Player extends disney.rabbitRivalry.ents.Entity
  2. {
  3.    var __currentWeapon;
  4.    var assetID;
  5.    var isCharging;
  6.    var isAttacking;
  7.    var isFlying;
  8.    var mc;
  9.    var gravityVector;
  10.    var __moveDt;
  11.    var __xAngleCalc;
  12.    var __yAngleCalc;
  13.    var __angle;
  14.    var __isPoweringUp;
  15.    var __power;
  16.    var __powerMeter_frames;
  17.    var nextY;
  18.    var startY;
  19.    var y;
  20.    var velocity;
  21.    var __animation;
  22.    var __isAnimating;
  23.    var isPerfect;
  24.    var didHit;
  25.    var __bounceCount;
  26.    var isAlive;
  27.    var x;
  28.    var hdReg;
  29.    var baseHeight;
  30.    var TYPE = "player";
  31.    var DRAWTYPE = "player";
  32.    var __DEF_ASSET = "yang_mc";
  33.    var __DEF_WIDTH = 120;
  34.    var __DEF_HEIGHT = 190;
  35.    var __USE_ACTUAL_DIMENSIONS = true;
  36.    var __DEF_HD_WIDTH = 80;
  37.    var __DEF_HD_HEIGHT = 160;
  38.    var __USE_DIMENSIONS_AS_HD = false;
  39.    var CUSTOMDRAW = true;
  40.    var __POWER_RATE = 100;
  41.    var __MAX_POWER = 100;
  42.    var __MIN_POWER = 30;
  43.    var __MINMAX_POWER_DIFF = disney.rabbitRivalry.ents.Player.prototype.__MAX_POWER - disney.rabbitRivalry.ents.Player.prototype.__MIN_POWER;
  44.    var __MIN_ANGLE = 270;
  45.    var __MAX_ANGLE = 350;
  46.    var __MAX_VELOCITY = 2800;
  47.    var __POWER_MULTIPLIER = 8.9;
  48.    function Player(t_data)
  49.    {
  50.       super(t_data);
  51.       this.__currentWeapon = 1;
  52.       if(disney.rabbitRivalry.GameState.getInstance().isYang)
  53.       {
  54.          this.assetID = "yang_mc";
  55.       }
  56.       else
  57.       {
  58.          this.assetID = "yin_mc";
  59.       }
  60.       this.isCharging = this.isAttacking = this.isFlying = false;
  61.    }
  62.    function equip(num)
  63.    {
  64.       this.__currentWeapon = num;
  65.       this.mc.anim.weapon.gotoAndStop(this.__currentWeapon);
  66.    }
  67.    function reset()
  68.    {
  69.       super.reset();
  70.       this.gravityVector = disney.rabbitRivalry.GameState.getInstance().GRAVITY;
  71.    }
  72.    function moveAndRender(camera, dt)
  73.    {
  74.       dt *= 2;
  75.       super.moveAndRender(camera,dt);
  76.    }
  77.    function update(dt)
  78.    {
  79.       this.__moveDt = dt * 1.5;
  80.       super.update(this.__moveDt);
  81.       if(this.isCharging)
  82.       {
  83.          this.__xAngleCalc = this.mc.center_mc._xmouse;
  84.          this.__yAngleCalc = this.mc.center_mc._ymouse;
  85.          if(this.__xAngleCalc >= 0)
  86.          {
  87.             if(this.__yAngleCalc >= 0)
  88.             {
  89.                this.__angle = 0;
  90.             }
  91.             else
  92.             {
  93.                this.__angle = 360;
  94.             }
  95.          }
  96.          else
  97.          {
  98.             this.__angle = 180;
  99.          }
  100.          this.__angle += Math.atan(this.__yAngleCalc / this.__xAngleCalc) * 57.29577951308232;
  101.          if(this.__angle > this.__MAX_ANGLE || this.__angle < 180)
  102.          {
  103.             this.__angle = this.__MAX_ANGLE;
  104.          }
  105.          else if(this.__angle < this.__MIN_ANGLE)
  106.          {
  107.             this.__angle = this.__MIN_ANGLE;
  108.          }
  109.          this.mc.angleBar_mc._rotation = this.__angle;
  110.          if(this.__isPoweringUp)
  111.          {
  112.             this.__power += this.__POWER_RATE * dt;
  113.             if(this.__power >= this.__MAX_POWER)
  114.             {
  115.                this.__power = this.__MAX_POWER;
  116.                this.__isPoweringUp = false;
  117.             }
  118.          }
  119.          else
  120.          {
  121.             this.__power -= this.__POWER_RATE * dt;
  122.             if(this.__power <= this.__MIN_POWER)
  123.             {
  124.                this.__power = this.__MIN_POWER;
  125.                this.__isPoweringUp = true;
  126.             }
  127.          }
  128.          this.mc.angleBar_mc.powerMeter_mc.gotoAndStop(Math.round((this.__power - this.__MIN_POWER) / this.__MINMAX_POWER_DIFF * this.__powerMeter_frames));
  129.       }
  130.       else if(this.isFlying)
  131.       {
  132.          this.addVelocity(this.gravityVector,this.__moveDt);
  133.          if(this.nextY > this.startY)
  134.          {
  135.             this.hitGround(this.startY);
  136.          }
  137.       }
  138.    }
  139.    function hitGround(t_y)
  140.    {
  141.       this.y = this.nextY = t_y;
  142.       this.isFlying = false;
  143.       this.animate("land");
  144.       this.velocity = new smashing.Point3D(0,0,0);
  145.    }
  146.    function grimace()
  147.    {
  148.       if(this.__animation != "hit")
  149.       {
  150.          disney.rabbitRivalry.Sounds.getInstance().p("yoHit" + Math.ceil(Math.random() * 2));
  151.       }
  152.       this.animate("hit");
  153.    }
  154.    function onMouseDown()
  155.    {
  156.       if(this.isCharging)
  157.       {
  158.          this.disablePowerAndAim();
  159.          this.animate("launch");
  160.          this.isAttacking = false;
  161.          return true;
  162.       }
  163.       return false;
  164.    }
  165.    function animate(frame)
  166.    {
  167.       super.animate(frame);
  168.       this.mc.anim.weapon.gotoAndStop(this.__currentWeapon);
  169.    }
  170.    function updateAnim()
  171.    {
  172.       if(this.__isAnimating)
  173.       {
  174.          if(this.mc.anim._currentFrame == this.mc.anim._totalFrames)
  175.          {
  176.             if(this.__animation == "launch")
  177.             {
  178.                this.animate("fly");
  179.                if(this.__angle < this.__MAX_ANGLE)
  180.                {
  181.                   this.__power -= 25 * (1 - (this.__angle - (this.__MIN_ANGLE - 1)) / (this.__MAX_ANGLE - this.__MIN_ANGLE));
  182.                }
  183.                this.__power = 30 + 70 * (this.__power / 100);
  184.                this.velocity = this.magnitudeToVector(this.__power * this.__POWER_MULTIPLIER,this.__angle);
  185.                this.isPerfect = true;
  186.                this.isFlying = true;
  187.             }
  188.             else if(this.__animation == "land")
  189.             {
  190.                if(this.y >= this.startY)
  191.                {
  192.                   this.animate("lose");
  193.                   smashing.keithm.Messenger.sendMessage("screen","runResultAnim",{type:"miss"});
  194.                   this.isAttacking = false;
  195.                }
  196.                else
  197.                {
  198.                   this.animate("attack_" + this.__currentWeapon);
  199.                   this.isAttacking = true;
  200.                   if(this.assetID == "yang_mc")
  201.                   {
  202.                      disney.rabbitRivalry.Sounds.getInstance().p("yangattack");
  203.                   }
  204.                   else
  205.                   {
  206.                      disney.rabbitRivalry.Sounds.getInstance().p("yinattack");
  207.                   }
  208.                }
  209.             }
  210.             else if(this.__animation.indexOf("attack_") > -1)
  211.             {
  212.                if(this.didHit)
  213.                {
  214.                   this.animate("win");
  215.                }
  216.                else
  217.                {
  218.                   this.animate("lose");
  219.                }
  220.                this.isAttacking = false;
  221.             }
  222.             else if(this.__animation == "win")
  223.             {
  224.                smashing.keithm.Messenger.sendMessage("world","goNextRabbit");
  225.                this.__animation = "freeze";
  226.             }
  227.             else if(this.__animation == "lose")
  228.             {
  229.                smashing.keithm.Messenger.sendMessage("world","onMiss");
  230.                this.__animation = "freeze";
  231.             }
  232.          }
  233.       }
  234.    }
  235.    function enablePowerAndAim()
  236.    {
  237.       this.animate(this.__IDLE_ANIMATION);
  238.       this.isCharging = true;
  239.       this.mc.angleBar_mc._visible = true;
  240.       this.didHit = false;
  241.       this.__power = this.__MIN_POWER;
  242.       this.__isPoweringUp = true;
  243.       this.__angle = 0;
  244.       this.__bounceCount = 0;
  245.    }
  246.    function disablePowerAndAim()
  247.    {
  248.       this.isCharging = false;
  249.       this.mc.angleBar_mc._visible = false;
  250.       this.mc.angleBar_mc.powerMeter_mc.gotoAndStop(1);
  251.       this.mc.angleBar_mc._rotation = 0;
  252.    }
  253.    function onDraw(newmc)
  254.    {
  255.       super.onDraw(newmc);
  256.       if(!this.isCharging)
  257.       {
  258.          this.disablePowerAndAim();
  259.       }
  260.       this.__powerMeter_frames = this.mc.angleBar_mc.powerMeter_mc._totalFrames;
  261.    }
  262.    function bounce(bounceRight)
  263.    {
  264.       if(this.__bounceCount > 2)
  265.       {
  266.          return undefined;
  267.       }
  268.       this.__bounceCount = this.__bounceCount + 1;
  269.       this.isPerfect = false;
  270.       if(bounceRight == true)
  271.       {
  272.          this.velocity.x = 90;
  273.       }
  274.       else
  275.       {
  276.          this.velocity.x = -60;
  277.       }
  278.       this.velocity.y = -100;
  279.    }
  280.    function runHD(t_target, dt)
  281.    {
  282.       if(!(this.isAlive && t_target.isAlive))
  283.       {
  284.          return false;
  285.       }
  286.       if(!this.isAttacking)
  287.       {
  288.          return super.runHD(t_target,dt);
  289.       }
  290.       if(t_target.x < this.x || !t_target.isDrawn)
  291.       {
  292.          return false;
  293.       }
  294.       if(this.mc.hitTest(t_target.mc))
  295.       {
  296.          return true;
  297.       }
  298.       return false;
  299.    }
  300.    function setHDRegistration()
  301.    {
  302.       this.hdReg = {};
  303.       this.hdReg.x = 0;
  304.       this.hdReg.y = - this.baseHeight / 2;
  305.    }
  306.    function isAttackFrame()
  307.    {
  308.       if(this.assetID == "yang_mc")
  309.       {
  310.          var _loc2_ = undefined;
  311.          if(this.__currentWeapon == 2)
  312.          {
  313.             _loc2_ = 6;
  314.          }
  315.          else
  316.          {
  317.             _loc2_ = 15;
  318.          }
  319.       }
  320.       else if(this.__currentWeapon == 3)
  321.       {
  322.          _loc2_ = 53;
  323.       }
  324.       else if(this.__currentWeapon == 2)
  325.       {
  326.          _loc2_ = 35;
  327.       }
  328.       else
  329.       {
  330.          _loc2_ = 19;
  331.       }
  332.       if(this.isAttacking && this.mc.anim._currentFrame > _loc2_)
  333.       {
  334.          return true;
  335.       }
  336.       return false;
  337.    }
  338. }
  339.